package com.example.byteinputstream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ByteStreamDemo5 {
    public static void main(String[] args) throws IOException {

        //创建对象
        FileInputStream fis = new FileInputStream("src/com/example/file/a.txt");

        //读取数据
        byte[] buf = new byte[2];

        int read1 = fis.read(buf);
        System.out.println(read1);
//        System.out.println(new String(buf));
        System.out.println(new String(buf, 0, read1));

        int read2 = fis.read(buf);
        System.out.println(read2);
//        System.out.println(new String(buf));
        System.out.println(new String(buf, 0, read2));

        int read3 = fis.read(buf);
        System.out.println(read3);
//        System.out.println(new String(buf));
        System.out.println(new String(buf, 0, read3));

        int read4 = fis.read(buf);
        System.out.println(read4);
        System.out.println(new String(buf));
        //错误
//        System.out.println(new String(buf, 0, read4));

        //关闭资源
        fis.close();

    }
}
